package com.hippo.liteflow.controller;

import com.hippo.core.pojo.vo.result.BaseResult;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import static com.hippo.core.pojo.vo.result.BaseResult.FAIL_CODE;

/**
 * @ClassName LiteFlowTestContriller
 * @Description TODO liteflow测试接口
 * @Author tangxl
 * @create 2023-04-03 08:26
 **/
@RestController
@RequestMapping(("/liteflow"))
@Tag(name = "liteflow测试")
public class LiteFlowTestContriller {
    @Resource
    private FlowExecutor flowExecutor;

    @Operation(summary = "数据库规则配置源流程测试",description = "数据库规则配置源流程测试")
    @GetMapping("/dbsql/test")
    public BaseResult sqlDbTestControl(@RequestParam String chanName){
        // 全节点平滑热刷新
        flowExecutor.reloadRule();
        // 执行流程
        LiteflowResponse response = flowExecutor.execute2Resp(chanName, "args");
        if (response.isSuccess()) {
            return BaseResult.ok();
        }else {
            return BaseResult.fail(FAIL_CODE, response.getMessage());
        }
    }
}
